package net.feling.mcloud.utils;

import android.util.Log;

import net.feling.mcloud.connection.ConnectService;
import net.feling.mcloud.entity.Message;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class DefaultClientHandler extends IoHandlerAdapter {

    public DefaultClientHandler() {
    }

    @Override
    public void sessionCreated(IoSession session) throws Exception {
        Log.d("session in sessionCreated", session.hashCode() + " ");
        System.out.println("sessionCreated");
    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        System.out.println("sessionOpened");
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        System.out.println("sessionIdle");
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        super.messageReceived(session, message);
        System.out.println("messageReceived");
        Message message1 = (Message) message;
        if (message1.getType().equals("".getClass().getSimpleName())) {
            System.out.println("this is recieve from Server--->" + message1.getContent());
        }
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        System.out.println("messageSent");
        System.out.println("session 的 ID: "+session.getId());
    }

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        Log.d("session in exceptionCaught", session.hashCode() + " ");
        System.out.println("exceptionCaught");
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        System.out.println("sessionClosed");

    }
}
